package com.swak.parser.exception;

import com.swak.parser.lexer.Lexer;
import com.swak.parser.lexer.LexerEngine;
import com.swak.parser.lexer.token.TokenType;

public class SqlParseException extends RuntimeException {

	private static final long serialVersionUID = 1L;

	public SqlParseException(final String errorMessage, final Object... args) {
		super(String.format(errorMessage, args));
	}

	public SqlParseException(final String message, final Exception cause) {
		super(message, cause);
	}

	public SqlParseException(final Exception cause) {
		super(cause);
	}

	private static final String UNMATCH_MESSAGE = "SQL syntax error, expected token is '%s', actual token is '%s', literals is '%s'.";

	private static final String TOKEN_ERROR_MESSAGE = "SQL syntax error, token is '%s', literals is '%s'.";

	private static final String UNSUPPORTED_MESSAGE = "Not supported token '%s'.";

	public SqlParseException(final Lexer lexer, final TokenType expectedTokenType) {
		super(String.format(UNMATCH_MESSAGE, expectedTokenType, lexer.getCurrentToken().getType(),
				lexer.getCurrentToken().getLiterals()));
	}

	public SqlParseException(final LexerEngine lexerEngine) {
		super(String.format(TOKEN_ERROR_MESSAGE, lexerEngine.getCurrentToken().getType(),
				lexerEngine.getCurrentToken().getLiterals()));
	}

	public SqlParseException(final TokenType tokenType) {
		super(String.format(UNSUPPORTED_MESSAGE, tokenType.toString()));
	}
}
